package com.sdl.timesblogmp.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import java.util.Date;

/**
 * @author sdl
 * @date 2020/5/10 11:27 下午
 * @description
 */
@Component
public class MybatisPlusConfig implements MetaObjectHandler {
    // 分页插件
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return  new PaginationInterceptor();
    }
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "gmtCreate", Date.class, new Date()); // 起始版本 3.3.0(推荐使用)
        this.fillStrategy(metaObject, "gmtCreate", Date.class);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "gmtModified", Date.class, new Date()); // 起始版本 3.3.0(推荐使用)
        this.fillStrategy(metaObject, "gmtModified", Date.class);
    }
}
